const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin'); //打包html

module.exports = {
    entry: './src/main.js',
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'bundle.js'
    },
    plugins: [new HtmlWebpackPlugin({
        template: './public/index.html'
    })],
    module: {
        rules: [
            // css处理
            {
                test: /\.css$/,
                use: [
                    'style-loader',
                    'css-loader'
                ]
            },
            // less处理
            {
                test: /\.less/,
                use: ['style-loader', 'css-loader', 'less-loader']
            },
            // 图片处理
            {
                test: /\.(png|svg|jpg|gif)$/,
                type: 'asset',
                // use: [
                //     'file-loader'
                // ]
            },
            // 处理字体
            {
                test: /\.(eot|svg|ttf|woff|woff2)$/,
                type: 'asset/resource',
                generator: {
                    filename: 'fonts/[name].[hash:6][ext]'
                }
            },
            // babel降级
            // {
            //     test: /\.m?js$/,
            //     exclude: /(node_modules|bower_components)/,
            //     use: {
            //         loader: 'babel-loader',
            //         options: {
            //             presets: ['@babel/preset-env']
            //         }
            //     }
            // }
        ]
    },
    devServer: {
        port: 8080
    }
}